package main

import (
	"fmt"
	"os"
	"go-iot/app/common/boot"
	"go-iot/app/api/web"
	"go-iot/app/iot/cluster"
	"go-iot/app/common/logger"
	"go-iot/app/common/config"
	"go-iot/app/common/mysql"
	"go-iot/app/common/redis"
	"go-iot/app/common/elasticsearch"
	"go-iot/app/iot/ruleengine"
	_ "go-iot/app/registry"
)

func main() {
	opt := config.New()
	msg, err := opt.Parse()
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", msg)
		os.Exit(1)
	}
	// 日志初始化
	logger.Init(opt)
	defer logger.Sync()
	logger.Infof(opt.Banner)
	// 集群配置
	cluster.Config(opt)
	// mysql配置
	mysql.Config(opt)
	// elasticsearch配置
	elasticsearch.Config(opt)
	// redis配置
	redis.Config(opt)
	// 规则引擎配置
	ruleengine.Config(opt)
	// 启动
	boot.CallStartLinstener()
	// 启动web服务
	web.MustNewServer(opt.APIAddr)
}
